-- summon_random_damage
-- create by zhuangsl
-- 技能：对随机一个怪物造成伤害
-- 配置：summon_continue_damage(2000)：2倍攻击伤害
return {
    apply = function(source, target, skillId, round, para, extra)
        -- 威力
        local force = para[1];

        -- 攻击方的攻击
        local attack = source:getAttack();

        -- 伤害
        local damage = math.modf(attack * force / 1000);

        -- 遍历所有的怪
        local ret = {};

        for p = 1, DUNGEON_WIDTH * DUNGEON_HEIGHT do
            local grid = DungeonM.getGridByPos(p);

            -- 是未死亡的怪物
            if  grid:isOpened() and
                grid:isMonster() and
                not grid.monster:isDead() then
                table.insert(ret, grid.monster);
            end
        end

        if #ret < 1 then
            return;
        end

        -- 随机选一个进行打击
        local rand = DungeonM.getRandSeed("summon_random_damage") % #ret;
        local monster = ret[rand + 1];

        -- 增加命中动作
        if SkillM.getSequence(monster) == nil then
            SkillM.getSequenceList()[monster] = CastSequence.create(source, monster, skillId);
        end
        SkillM.getSequence(monster):hit(source, monster, skillId);

        -- 受创
        CombatM.receiveDamage(source, monster, damage, skillId, extra);

        -- 作用目标
        return ret;
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]),};
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        -- 威力
        local force = para[1];

        -- 攻击
        local attack = source:getAttack();

        -- 伤害
        local damage = math.modf(force * attack / 1000);

        desc = string.gsub(desc, "{damage}", damage);

        return desc;
    end,
};
